import axios from "axios";

axios.defaults.baseURL='/api'

const request = axios.create({
    timeout:5000
})

// 请求拦截器
request.interceptors.request.use(config=>{
   const token = sessionStorage.getItem("token")||localStorage.getItem("token")||null
   if(token){
        config.headers.Authorization = token
   } 
//    token续期
   if(localStorage.getItem("token")){
        config.headers['rememberMe'] = true
   }else{
        config.headers['rememberMe'] = false
   }
   
   return config
},err=>{
    return Promise.reject(err)
})

// 响应拦截器
request.interceptors.response.use(res=>{
    return res
},err=>{
    return Promise.reject(err)
})

export default request